﻿using System;
using NLog;
using NLog.Config;
using NLog.Targets;

namespace UIExceptionHandler
{
    public class LogHelper
    {
        public static string ExceptionLogFileName = "Exceptions.log";
        public static Logger Logger;

        static LogHelper()
        {
            SetupLogger();
        }

        public static void SetupLogger()
        {
            ConfigureNlog();
            Logger = LogManager.GetCurrentClassLogger();
            Logger.Trace("Version: {0}", Environment.Version.ToString());
            Logger.Trace("OS: {0}", Environment.OSVersion.ToString());
        }

        private static void ConfigureNlog()
        {
            var config = new LoggingConfiguration();

            var fileTarget = new FileTarget();
            config.AddTarget("file", fileTarget);

            fileTarget.Layout = @"${longdate} ${message}";
            fileTarget.FileName = "${basedir}/" + ExceptionLogFileName;

            var rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
            config.LoggingRules.Add(rule2);

            LogManager.Configuration = config;
        }
    }
}
